package collections.list;

import com.google.common.collect.Lists;
import org.junit.Test;

import java.io.File;
import java.util.*;

public class ListDemo {

  @Test
  public void test2() {

    /*
     *  Stack栈 pop() 跟 push() 配合使用
     */
    Deque stack = new LinkedList<String>();
    stack.push("第一个元素");
    stack.push("第二个元素");
    stack.pop();
    stack.push("第三个元素");

    System.out.println(stack);




//    Deque list = new LinkedList<Integer>();
//    list.add(1);
//    list.add(2);
//    list.pop();
//    list.add(3);
//    System.out.println(list);

  }

  @SuppressWarnings("unchecked")
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.println((222.3332 - 222.33) > 0);
    List<Float> list = new ArrayList<Float>() {
      {
        add(new Float(12.2));
        add(new Float(222.33));
        add(new Float(222.33));
        add(new Float(12.2));
        add(new Float(222.33));
        add(new Float(12.2));
        add(new Float(222.33));
        add(new Float(12.2));
        add(new Float(222.3332));
        add(new Float(12.2));
      }
    };

//    Collections.sort(list, new Comparator() {
//      @Override
//      public int compare(Object o1, Object o2) {
//        // TODO Auto-generated method stub
//        float f1 = (float) o1;
//        float f2 = (float) o2;
//        return (int) (f2 - f1);
//      }
//    });
//

//    list.sort(new Comparator<Float>() {
//      @Override
//      public int compare(Float o1, Float o2) {
//        return o1.compareTo(o2);
//      }
//    });


    list.sort(null);
    System.exit(0);

    for (Float f : list) {
      System.out.println(f);
    }
  }

  @Test
  public void test() {
    List<Field> entryss = Lists.newArrayListWithExpectedSize(10);
    for (int i = 0; i < 15; i++) {
      entryss.add(new Field(i));
    }

    Field[] fields = new Field[entryss.size()];
    entryss.toArray(fields);

    System.out.println(Arrays.toString(fields));

  }

  class Field {
    public int key;
    public int val;

    public Field(int key) {
      this.key = key;
    }

    @Override
    public String toString() {
      return "Field{" +
              "key=" + key +
              ", val=" + val +
              '}';
    }
  }


  @Test
  public void test1() {

    new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          //
          long l = Runtime.getRuntime().totalMemory();
          //
          long freeMemory = Runtime.getRuntime().freeMemory();
          System.out.println((l - freeMemory) / (1024 * 1024) + " mb");
        }
      }
    }).start();

    List<LocalGsPoiTripShootPO> entryss = Lists.newArrayListWithExpectedSize(100000);
    for (int i = 0; i < 40000000; i++) {
      LocalGsPoiTripShootPO e = new LocalGsPoiTripShootPO();
      e.poiId = 12123;
      entryss.add(e);
    }


  }

}
